<?php
    include_once($_SERVER['DOCUMENT_ROOT'].'/mba/models/Database.php');
	
    class DonVi extends Database{
		private $MA_DON_VI;
		private $TEN_DON_VI;
		private $DIA_CHI_DV;
		private $LIEN_HE_DV;
		private $TEN_TK;
		private $MAT_KHAU;
		private $QUYEN;
		
		
		public function setMaDV($MADV){
			$this->MA_DON_VI = $MADV;
			}
		public function getMaDV(){
			return $this->MA_DON_VI;
			}
        
        public function setTenDV($TENDV){
            $this->TEN_DON_VI = $TENDV;
        }
        public function getTenDV(){
            return $this->TEN_DON_VI;
        }
		
		 public function setDiaChiDV($DiaChiDV){
            $this->DIA_CHI_DV = $DiaChiDV;
        }
		public function getDiaChiDV(){
            return $this->DIA_CHI_DV;
        }
		
		 public function setLienHeDV($LienHeDV){
            $this->LIEN_HE_DV = $LienHeDV;
        }  
		public function getLienHeDV(){
            return $this->LIEN_HE_DV;
        }
		public function setTenTK($TaiKhoan){
			$this->TEN_TK = $TaiKhoan;
		}
		public function getTenTK(){
			return $this->TEN_TK;
		}
		public function setMatKhau($MatKhau){
			$this->MAT_KHAU = $MatKhau;
		}
		public function getMatKhau(){
			return $this->MAT_KHAU;
		}
		public function setQuyen($Quyen){
			$this->QUYEN = $Quyen;
		}
		public function getQuyen(){
			return $this->QUYEN;
		}
		// function them thong tin don vi
		 public function themDV(){
            $query = "insert into don_vi(MA_DON_VI,TEN_DON_VI,DIA_CHI_DV,LIEN_HE_DV) 
            values ('".$this->getMaDV()."','".$this->getTenDV()."','".$this->getDiaChiDV()."','".$this->getLienHeDV()."')";
            $this->setQuery($query);
            $this->executeQuery();
			$query = "insert into tai_khoan(TEN_TK,MAT_KHAU,MA_DON_VI,QUYEN) 
            values ('".$this->getTenTK()."','".$this->getMatKhau()."','".$this->getMaDV()."','".$this->getQuyen()."')";
            $this->setQuery($query);
            return $this->executeQuery();
        }
		
                
       // function sua thong tin don vi
        public function suaDV(){
            $query = "	update don_vi 
						set TEN_DON_VI='".$this->getTenDV()."',
						DIA_CHI_DV='".$this->getDiaChiDV()."',
						LIEN_HE_DV='".$this->getLienHeDV()."'
						where MA_DON_VI='".$this->getMaDV()."' ";
            $this->setQuery($query);
			$this->executeQuery();
			
			$query = "	update tai_khoan 
						set TEN_TK='".$this->getTenTK()."',
						MAT_KHAU='".$this->getMatKhau()."',
						QUYEN='".$this->getQuyen()."'
						where MA_DON_VI='".$this->getMaDV()."' ";
            $this->setQuery($query);
            return $this->executeQuery();  
        }
		// function xoa thong tin don vi
        public function xoaDV(){
            $this->setQuery("delete from don_vi where  MA_DON_VI='".$this->getMaDV()."'");
			$this->executeQuery();
			$this->setQuery("delete from tai_khoan where  MA_DON_VI='".$this->getMaDV()."'");
            return $this->executeQuery();
        }
     
        public function dsDonVi(){
            $this->setQuery("select don_vi.MA_DON_VI,TEN_DON_VI,DIA_CHI_DV,LIEN_HE_DV,TEN_TK,MAT_KHAU,QUYEN
							 from don_vi,tai_khoan
							 WHERE don_vi.MA_DON_VI=tai_khoan.MA_DON_VI");
            return $this->fetchAll();
        }
	
    }
	
	
	
?>